package com.hdax.dmw.scheduler.mapstruct;

import com.hdax.dmw.dtos.scheduler.PriceDto;
import com.hdax.dmw.entity.scheduler.DmSchedulerSeat;
import com.hdax.dmw.entity.scheduler.DmSchedulerSeatPrice;
import com.hdax.dmw.scheduler.service.DmSchedulerSeatService;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Mapper(componentModel = "spring")
public abstract class PriceDtoMapper {
    @Mappings({
            @Mapping(target = "isHaveSeat",expression = "java(isHaveSeat(source.getSeatNum(),source.getScheduleId()))")
    })
    public abstract PriceDto toTarget(DmSchedulerSeatPrice source);
    public abstract List<PriceDto> toTargetList(List<DmSchedulerSeatPrice> sources);

    @Autowired
    private DmSchedulerSeatService seatService;

    public Short isHaveSeat(Integer seatNum,Long scheduleId ){
        int saleSeatCount = seatService.getSaleCount(scheduleId);
        if(saleSeatCount == seatNum){
            return 0;//没有座位
        }
        return 1;//还有剩余座位
    }

}
